<template>
  <div id="jianzhuGS">
    <van-tabs v-model="active" @click="handleclickto" swipeable>
      <van-tab title="我的待办">
        <ul>
          <!-- <div style="border-top: 1px solid #d2d2d2; margin-top: 4px; clear: both"></div> -->
          <div class="SQList" ref="SQList">
            <van-search background="#fff" v-model="value1" placeholder="请输入姓名" @search="serachData" />
            <li v-show="contentData.length > 0" v-for="(item, index) in contentData" @click="contentDataClick(item)"
              :key="index">
              <p style="font-weight: bold; height: 28px">
                <span style="float: left">{{ item.NODE_NAME }}</span>
                <span style="float: right">{{ item.HOUSEAPPLICANT }}</span>
              </p>
              <p style="font-size: 14px; color: #848484; height: 28px">
                <span style="float: left">进度：{{ item.PROC_NAME }}</span>
                <span style="float: right">{{ item.APPLYTIME }}</span>
              </p>
              <p style="font-size: 14px; color: #848484; height: 20px">
                <span style="float: left">地址：{{ item.PERMANENTADDR ? item.PERMANENTADDR : '暂无数据' }}</span>
              </p>
            </li>
          </div>
          <div style="height: 60vh; text-align: center; padding-top: 20vh" v-show="noData">
            <div style="margin-bottom: 10px">
              <img src="https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/DSF/50.png" />
            </div>
            <div>暂无数据</div>
          </div>
        </ul>
      </van-tab>
      <van-tab title="申请记录">
        <myshenQing></myshenQing>
      </van-tab>
    </van-tabs>
    <div class="bottom">
      <ul>
        <li v-for="(item, index) in bottomData" :key="index" @click="bottomClick(index)"
          v-show="($store.state.isGJ && (item.name === '首页' || item.name === '我的待办' || item.name === '我的收藏')) || (!$store.state.isGJ && (item.name === '首页' || item.name === '我的待办'))"
          :style="{
            color: nowIndex === index ? '#007AFF' : '#908f94',
            fontSize: '18px',
            width: $store.state.isGJ ? '33.3%' : '50%'
          }">
          <img v-if="nowIndex === index" :src="item.icon" />
          <img v-else :src="item.icons" />
          <p>{{ item.name }}</p>
        </li>
      </ul>
    </div>
    <van-popup v-model="shoulm1">
      <div class="con_box">
        <h3>{{ text1.title }}</h3>
        <p>{{ text1.message }}</p>
        <div class="btnv">
          <span @click="handleClose1()" v-if="text1.btn.cancelText">
            {{ text1.btn.cancelText }}
          </span>
          <span @click="handleOk1(SaveData)" v-if="text1.btn.okText">
            {{ text1.btn.okText }}
          </span>
        </div>
      </div>
    </van-popup>
    <van-popup v-model="shoulm1">
      <div class="con_box">
        <h3>{{ text.title }}</h3>
        <p>{{ text.message }}</p>
        <div class="btnv">
          <span @click="handleClose1()" v-if="text.btn.cancelText">
            {{ text.btn.cancelText }}
          </span>
          <span @click="handleOk1()" v-if="text.btn.okText">
            {{ text.btn.okText }}
          </span>
        </div>
      </div>
    </van-popup>
  </div>
</template>

<script>
import { QuerySignCallback, JFDataList, FileServerProxy, QueryListToGJORFW, housePublichouseRemoldUnitBuildPerson } from '../../utils/api'
import { GJDBFunction, GJDBFunction2 } from '../../utils/queryData'
import myshenQing from './myshenQing.vue'
import BScroll from 'better-scroll'
import { isLinAn } from '@/utils/isLinAn'
export default {
  name: 'jianzhuGS',
  data() {
    return {
      noData: false,
      ISGJ: false,
      value1:'',
      handleGoto: 0,
      nowIndex: 1,
      newItem: [],
      tableData: {},
      active: 'first',
      contentData: [
       
      ],
      text1: {
        title: '提示',
        message: '请确认是否需要更换工匠?',
        btn: {
          okText: '确定',
          cancelText: '取消'
        }
      },
      shoulm1: false,
      shenkaobeiData:[],
      contentData1: [
        {
          name: '我要建房申请',
          num: 0
        },
        {
          name: '我的贷款申请',
          num: 0
        },
        {
          name: '我购买的保险',
          num: 0
        },
        {
          name: '我要改扩建申请',
          num: 0
        },
        {
          name: '我要危改申请',
          num: 0
        },
        {
          name: '我要流转申请',
          num: 0
        },
        {
          name: '我要办理不动产权证申请',
          num: 0
        }
      ],
      shoulm1: false,
      text: {
        title: '提示',
        message: '是否更换工匠?',
        btn: {
          okText: '确定',
          cancelText: '取消'
        }
      },
      bottomData: [
        {
          name: '首页',
          icon: 'https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/ZLJ/20.png',
          icons: 'https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/ZLJ/20-1.png'
        },
        {
          name: '我的待办',
          icons: 'https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/ZLJ/21.png',
          icon: 'https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/ZLJ/21-1.png'
        },
        {
          name: '我的收藏',
          icons: 'https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/ZLJ/22.png',
          icon: 'https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/ZLJ/22-1.png'
        }
      ]
    }
  },
  components: {
    myshenQing
  },
  updated () {
        this.$nextTick(function () {
            let position = this.$store.state.jianzhuGS //返回页面取出来
            const content = document.querySelector('#jianzhuGS')
            content.scrollTop = position
        })
    },
    beforeRouteLeave (to, from, next) {
        const content = document.querySelector('#jianzhuGS')
        let position = content.scrollTop
        console.log(position)
        this.$store.commit('getjianzhuGS', position) //离开路由时把位置存起来
        next()
    },
  methods: {
    serachData(val) {
      if (!val) return this.contentData = this.shenkaobeiData
      this.contentData = this.shenkaobeiData.filter(item => {
        return item.HOUSEAPPLICANT && item.HOUSEAPPLICANT.indexOf(val) > -1
      })
    },
    handleClose1() {
      this.shoulm1 = false
    },
    handleOk1() {
      //直接发送
      //this.shoulm1 = true;
      this.$router.push({
        path: '/TreeSelect',
        query: { data: this.newItem, isnhzg: 1 }
      })
    },
    bottomClick(index) {
      switch (index) {
        case 0:
          this.$router.push({
            path: '/ZLJIndex'
          })
          break
        case 1:
          this.$router.push({
            path: 'MyAgent'
          })
          break
        case 2:
          this.$router.push({
            path: 'MyEnshrine'
          })
          break
      }
    },
    handleclickto(data) {
      console.log(data)
      if (data == '1') {
        this.$store.commit('getContent', [])
      }
    },
    async getListData(item) {
      //改变当前citycode
      if (item.s) {
        // window.localStorage.setItem('citycode', item.s)
        if (item.cun !== null) {
          const res = await isLinAn(item.cun)
          if (res) {
            window.localStorage.setItem('citycode', '330112000000')
          } else {
            let code1 = item.cun.slice(0, 4) + '00000000'
            window.localStorage.setItem('citycode', code1)
          }
        } else {
          window.localStorage.setItem('citycode', '441300000000')
        }
      }

      let isNHApplyParamNH = {
        procName: 'ZJBXDBX',
        dtParams: JSON.stringify([{ I_USERID: "'" + item.rowGuid + "'", I_SJH: "'" + item.serialNumber + "'" }]),
        token: window.localStorage.getItem('token')
      }
      let xcfycjtfnApplynh = {
        accessCode: '69db6bece3a7480592e2ec753d1e335e',
        cityCode: window.localStorage.getItem('citycode') ? window.localStorage.getItem('citycode') : '441300000000',
        params: isNHApplyParamNH
      }
      const resxcfycjtApplynh = await FileServerProxy(xcfycjtfnApplynh)
      let data = JSON.parse(resxcfycjtApplynh.data.data).Data[0]
      if (data) {
        this.contentDataClick(data)
      } else {
        //跳转
        debugger
        console.log(item)
        if (item.PROC_GUID) {
          this.getDataJD(item)
        } else {
          this.$toast.fail('当前案卷村委暂未受理')
        }
      }
    },
    //获取阶段数据
    async getDataJD(item) {
      this.$router.push({
        path: '/KeyLine',
        query: { PROC_GUID: item.PROC_GUID }
      })
    },
    contentDataClick(item) {
      debugger
      console.log(item, 'hahahahah')
      window.localStorage.setItem('UUID1', '')
      window.sessionStorage.setItem('PKID', item.PKID)
      window.sessionStorage.setItem('ROW_GUID1', JSON.stringify(item))
      //需要判断当前是不是工匠 工匠页面需要展示多条
      if (item.NODE_NAME === '农户选图集、选工匠') {
        //农户选图集、选工匠 签合同环节
        this.handleGoto = 0
      } else if (
        (item.NODE_GUID === '{FAFEF7FF-6294-489A-A5DF-53906712EBEE}' || item.NODE_GUID === '{FEF0E7B0-F048-42E0-998E-06387B0D03DB}') &&
        (item.HTBHQDZT == null || item.F_JZQYSGFZR == null || item.F_JZQYXMFZR == null)
      ) {
        //获取数据 工匠签合同环节
        debugger
        this.handleGoto = 1
      } else if (
        (item.NODE_GUID === '{FAFEF7FF-6294-489A-A5DF-53906712EBEE}' || item.NODE_GUID === '{FEF0E7B0-F048-42E0-998E-06387B0D03DB}') &&
        item.HTBHQDZT != null &&
        item.F_JZQYSGFZR != null &&
        item.F_JZQYXMFZR != null
      ) {
        if (!this.$store.state.isGJ) {
          this.$toast.fail('请前往我的项目办理')
          this.handleGoto = -1
        } else {
          this.handleGoto = 4
        }
      } else if (item.NODE_NAME === '基槽验线') {
        // if (!this.$store.state.isGJ) {
        //   this.$toast.fail('请前往我的项目办理')
        //   this.handleGoto = -1
        // } else {
        this.handleGoto = 6
        // }
      } else if (item.NODE_NAME == '一层立模') {
        // if (!this.$store.state.isGJ) {
        //   this.$toast.fail('请前往我的项目办理')
        //   this.handleGoto = -1
        // } else {
        this.handleGoto = 8
        // }
      } else if (item.NODE_NAME === '竣工验收') {
        //获取数据
        // if (!this.$store.state.isGJ) {
        //   this.$toast.fail('请前往我的项目办理')
        //   this.handleGoto = -1
        // } else {
        this.handleGoto = 7
        // }
      } else if (
        item.NODE_GUID == '{D2048C7B-88F9-453C-8FB9-6CFBE287634F}' ||
        item.NODE_GUID == '{0A7F08C3-5939-4254-A437-9468ABF192D5}' ||
        item.NODE_GUID == '{757359B4-6AC2-4860-899F-94A348EC0177}' ||
        item.NODE_GUID == '{B6C36D7F-E42E-49EC-B7EA-9CCF2449DB2A}' ||
        item.NODE_GUID == '{0C629D9A-8AFB-4012-A4CC-4D870229DC38}' ||
        item.NODE_GUID == '{B3ACD6E6-CD10-42B4-9C36-B981DA0129E4}' ||
        item.NODE_GUID == '{FB74960E-0585-4B35-842F-D5DDEF3E00F3}'
      ) {
        //现场放养农户整改
        debugger
        this.handleGoto = 20
      } else {
        this.getDataJD(item)
        // this.$notify({ type: "warning", message: "当前环节不需要处理!" });
        this.handleGoto = -1
      }
      // } else {

      // }
      this.$store.commit('gettoGuid', item)
      this.$store.commit('getHJZT', this.handleGoto)
      //跳转到选择工匠页面 //
      if (this.handleGoto == 0) {
        if (item.BUILDTYPE == 14) {
          window.localStorage.setItem('SSZZ_CITYNAME', item.VILLAGE)
        } else {
          window.localStorage.setItem('TOWN_CITYNAME', item.CUN)
        }
        window.localStorage.setItem('GJRowGUID', item.ROW_GUID)
        window.localStorage.setItem('XTXGJGJID', item.GJID)
        this.$router.push({
          path: '/ChooseCraftsman'
        })
        this.$store.commit('getXTXGJData', item)
      } else if (this.handleGoto == 1) {
        //签订合同页面
        debugger
        console.log(item.HTQDZT, item.HTBHQDZT, '哈哈哈哈哈哈哈')
        if (item.HTBHQDZT == null || item.F_JZQYSGFZR == null || item.F_JZQYXMFZR == null) {
          window.localStorage.setItem('UUID1', '')
          debugger
          console.log(item, 'jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj')
          this.tableData = item
          //农户点击签合同件需要提示是否更换工匠
          this.$router.push({
            path: '/ConstructionContract',
            query: { data: JSON.stringify(item) }
          })
        }
      } else if (this.handleGoto == 20) {
        // this.shoulm1 = true
        this.newItem = item
      } else if (this.handleGoto != -1 && this.handleGoto != 10 && this.handleGoto != 11 && this.handleGoto != 12 && this.handleGoto != 13) {
        this.$router.push({
          path: '/CompletionAcceptance',
          query: { data: JSON.stringify(item) }
        })
      }
    },
    handleOk1(data) {
      // this.handleButton();
      //更换工匠 标识
      window.sessionStorage.setItem('ChangeGJ', true)
      //跳入更换工匠页面
      this.$router.push({
        path: 'craftsmanServices',
        query: {
          id1: '更换工匠',
          dataValue: JSON.stringify(this.tableData)
        }
      })
    },
    handleClose1() {
      this.shoulm1 = false
      this.$router.push({
        path: '/ConstructionContract',
        query: { data: JSON.stringify(this.tableData) }
      })
    },
    getcontentData: async function (data) {
      this.shenkaobeiData=[];
    //   this.contentData = []
      this.contentData1[0].num = 0
      //建筑公司接口请求
      //先获取建筑公司的统一社会信用代码
      let data2 = {
        username: window.localStorage.getItem('DanDianPhone')
      }
      const res11 = await housePublichouseRemoldUnitBuildPerson(data2)
      if (res11.data.data.length > 0) {
        res11.data.data.forEach(async (item) => {
          let data1 = [
            {
              I_USERID: item.uscc,
              I_TYPE: '1',
              I_TYSHXYDM: item.uscc
            }
          ]
          const res = await GJDBFunction2('BUILDER', data1)
          this.shenkaobeiData.push(...res);
          this.contentData.push(...res)
          this.contentData.length == 0 ? (this.noData = true) : (this.noData = false)
        })

        console.log(this.contentData.length, this.noData, 'this.noData')
        this.$nextTick(() => {
          this.scroll = new BScroll(this.$refs.SQList, {
            click: true
          })
        })
      } else {
        // this.contentData = []
        this.contentData.length == 0 ? (this.noData = true) : (this.noData = false)
        this.$toast.fail('未查到所属建筑公司')
      }
    }
  },
  mounted() {
    if (!this.$store.state.isGJ) {
      this.ISGJ = true
    }
    this.getcontentData()
    if (ZWJSBridge) {
      ZWJSBridge.setTitle({
        title: '建筑企业待办'
      })
        .then((res) => { })
        .catch((err) => { })
    }
  }
}
</script>

<style scoped lang="scss">
#jianzhuGS {
  height: 94vh;
  font-family: 'Helvetica Neue', Helvetica, STHeiTi, sans-serif;
  font-size: 14px;
  overflow: auto;
  // font-family: 黑体;
  .SQList {
    width: 100vw;
    height: calc(100vh - 100px);
    background: #fff;

    // padding: 0 10px;
    li {
      padding-top: 4px;
      // border-bottom: 1px solid #d2d2d2;
      background-color: white;
      // margin: 14px 10px;
      border-radius: 10px;
      padding: 10px;
      width: 96%;
      margin: 0 auto;
      margin-top: 0.14rem;
      color: black;
      box-shadow: 0 0 0.16rem #e3e3e3;
    }
  }

  /*padding: 10px;*/

  .bottom {
    clear: both;
    position: fixed;
    bottom: 0;
    // height: 100px;
    width: 100%;
    text-align: center;
    height: 36.5px;
    background: #ffffff;
    border-top: 1px solid #d2d2d2;

    ul {
      width: 100%;
      height: 100%;
      clear: both;
      overflow: hidden;
      display: flex;
      align-items: center;

      li {
        float: left;
        width: 33.3%;
        font-size: 14px !important;

        img {
          height: 14px;
          margin-bottom: 0.02rem;
        }
      }
    }
  }

  .van-popup {
    border-radius: 10px;

    .con_box {
      width: 270px;
      line-height: 1;
      text-align: center;
      color: #4d5c82;
      padding: 15px;
      box-sizing: border-box;

      >h3 {
        font-size: 20px;
        margin-top: 10px;
        margin-bottom: 20px;
      }

      >p {
        font-size: 17px;
        margin-bottom: 30px;
      }

      .btnv {
        display: flex;
        justify-content: space-between;

        >span {
          display: block;
          width: 114px;
          background-color: #e0e5f5;
          text-align: center;
          line-height: 44px;
          font-size: 17px;
        }

        >span:last-of-type {
          background-color: #1288fe;
          color: #ffffff;
        }
      }
    }
  }
}
</style>
